<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="基地名称" prop="ebBaseName">
        <el-input
          v-model="queryParams.ebBaseName"
          placeholder="请输入基地名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="所在省市" prop="ebAddress">-->
<!--        <el-input-->
<!--          v-model="queryParams.ebAddress"-->
<!--          placeholder="请输入所在省市"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="投产日期" prop="ebProductionDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.ebProductionDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择投产日期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="生产线(条)" prop="ebProductionLine">-->
<!--        <el-input-->
<!--          v-model="queryParams.ebProductionLine"-->
<!--          placeholder="请输入生产线(条)"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="产品固定产能(万台/年)" prop="ebFixedCapacity">-->
<!--        <el-input-->
<!--          v-model="queryParams.ebFixedCapacity"-->
<!--          placeholder="请输入产品固定产能(万台/年)"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="满产产能(万台)" prop="ebMaxCapacity">-->
<!--        <el-input-->
<!--          v-model="queryParams.ebMaxCapacity"-->
<!--          placeholder="请输入满产产能(万台)"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="现货库存(万台)" prop="ebInventory">-->
<!--        <el-input-->
<!--          v-model="queryParams.ebInventory"-->
<!--          placeholder="请输入现货库存(万台)"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="品牌" prop="ebBrand">
        <el-input
          v-model="queryParams.ebBrand"
          placeholder="请输入品牌"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="产品形态" prop="ebForm">-->
<!--        <el-input-->
<!--          v-model="queryParams.ebForm"-->
<!--          placeholder="请输入产品形态"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="年度产能(万台)当前年" prop="ebCurrentCapacity">-->
<!--        <el-input-->
<!--          v-model="queryParams.ebCurrentCapacity"-->
<!--          placeholder="请输入年度产能(万台)当前年"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="年度产能(万台)下一年" prop="ebNextRoadmap">-->
<!--        <el-input-->
<!--          v-model="queryParams.ebNextRoadmap"-->
<!--          placeholder="请输入年度产能(万台)下一年"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['info:base:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['info:base:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['info:base:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['info:base:importPage']"
        >批量导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['info:base:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="data" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="基地名称" align="center" prop="ebBaseName" />
      <el-table-column label="所在省" align="center" prop="province" />
      <el-table-column label="所在市" align="center" prop="city" />
      <el-table-column label="状态" align="center" prop="ebStatus" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.base_status" :value="scope.row.ebStatus"/>
        </template>

      </el-table-column>
      <el-table-column label="投产日期" align="center" prop="ebProductionDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ebProductionDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="建厂形式" align="center" prop="ebFactoryType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.factory_type" :value="scope.row.ebFactoryType"/>
        </template>
      </el-table-column>
      <el-table-column label="生产线(条)" align="center" prop="ebProductionLine" />
      <el-table-column label="审核状态" align="center" prop="ebState" >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.ebState === '0'" type="info">待审核</el-tag>
          <el-tag v-if="scope.row.ebState === '1'" type="error">不合格</el-tag>
          <el-tag v-if="scope.row.ebState === '2'" >正常</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['info:base:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(scope.row)"
            v-hasPermi="['info:base:detail']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['info:base:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import ListMixin from "@/minixs/list"
import request from "@/utils/request";
export default {
  name: "list",
  mixins:[ListMixin],
  dicts:['base_status','factory_type'],
  data() {
    return {
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ebName: null,
        ebBaseName: null,
        ebAddress: null,
        ebStatus: null,
        ebProductionDate: null,
        ebFactoryType: null,
        ebProductionLine: null,
        ebFixedCapacity: null,
        ebMaxCapacity: null,
        ebInventory: null,
        ebBrand: null,
        ebForm: null,
        ebCurrentCapacity: null,
        ebNextRoadmap: null,
      },
    //   删除地址
      deletedUrl:"/info/base/"
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询企业基地列表 */
    getList() {
      this.loading = true;
      request({
        url: '/info/base/list',
        method: 'get',
        params: this.queryParams
      }).then(response => {

        this.data = response.rows.map(item=>{
          const citys = item.ebCity.split(",")
          if(citys.length >= 2){
            item.province = citys[0]
            item.city = citys[1]
          }
          return item;
        });
        this.total = response.total;
        this.loading = false;
      });
    },
    handleImport(){
      this.$emit("import-handle", {
        open: true,
        title: "批量导入",
        type:'IMPORT'
      })
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('/info/base/export', {
        ...this.queryParams
      }, `企业基地_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
